package com.zhiwei.codesecurity.common.webservice.checkmarx.wsdk.client;

import com.zhiwei.codesecurity.common.webservice.checkmarx.v7.*;
import com.zhiwei.codesecurity.common.webservice.checkmarx.wsdk.args.ZipArgs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ZipSDKClient extends SDKClient<ZipArgs> {
    private final static Logger logger = LoggerFactory.getLogger(ZipSDKClient.class);

    public ZipSDKClient(ZipArgs zipArgs) {
        super(zipArgs);
    }

    /**
     * Create SourceCodeSettings; 配置源码获取相关属性
     * @return
     */
    public SourceCodeSettings createSourceCodeSettings() {
        logger.info(">>>>>>>>开始设置本地上传扫描代码配置");
        LocalCodeContainer container = new LocalCodeContainer();
        container.setFileName(this.args.getZipName());
        container.setZippedFile(this.args.getZipBytes());
        logger.info(">>>>>>>LocalCodeContainer设置完成|container:{}", container);

        SourceCodeSettings codeSettings = new SourceCodeSettings();
        codeSettings.setSourceOrigin(SourceLocationType.LOCAL);
        codeSettings.setPackagedCode(container);
        logger.info(">>>>>>>SourceCodeSettings设置完成|codeSettings:{}", container);
        return codeSettings;
    }

    public static void main( String[] args ) throws FileNotFoundException, IOException {
        ZipArgs zipArgs = new ZipArgs();
        zipArgs.setSdkUrl("http://61.147.125.143:1088/cxwebinterface/sdk/cxsdkwebservice.asmx?wsdl");
        zipArgs.setSdkUsr("admin");
        zipArgs.setSdkPwd("Admin@2018");
//        zipArgs.setPreset("All");
//        zipArgs.setGroup("CxServer");
//        zipArgs.setConfig("Default Configuration");
//        zipArgs.setProjectName("测试项目名称");
//        // zipArgs.setProjectId(-1L);
//        zipArgs.setOwner("zhangxian");
//        zipArgs.setDescription("测试描述文字");
//        zipArgs.setZipName("codesecurity-service.zip");
//        File file = new File("D:\\codesecurity-service.zip");
//        FileInputStream inputStream = new FileInputStream(file);
//        byte[] bytes = new byte[inputStream.available()];
//        inputStream.read(bytes);
//        inputStream.close();
//        zipArgs.setZipBytes(bytes);

        ZipSDKClient zipSDKClient = new ZipSDKClient(zipArgs);
//        CxWSResponseProjectScannedDisplayData displayData =
//                zipSDKClient.sdk.getProjectScannedDisplayData(zipSDKClient.sessionId);
//        CxWSResponseScansDisplayData displayData =
//                zipSDKClient.sdk.getScansDisplayDataForAllProjects(zipSDKClient.sessionId);
        SDKClient.getScanDisplayData(zipSDKClient);
        int i = 10;
    }
}
